package com.csj.DesignPattern.state.before;

public class Lift implements ILift{

    private int state;

    @Override
    public void setState(int state) {
        this.state = state;
    }

    @Override
    public void open() {
        if (state == CLOSE_STATE) {
            System.out.println("电梯门开启");
            setState(OPEN_STATE);
        }
        if (state == STOP_STATE) {
            System.out.println("电梯门开启");
            setState(OPEN_STATE);
        }
    }

    @Override
    public void close() {
        if (state == OPEN_STATE) {
            System.out.println("电梯门关闭");
            setState(CLOSE_STATE);
        }
    }

    @Override
    public void run() {
        if (state == STOP_STATE) {
            System.out.println("电梯运行");
            setState(RUNNING_STATE);
        }
        if (state == CLOSE_STATE) {
            System.out.println("电梯运行");
            setState(RUNNING_STATE);
        }

    }

    @Override
    public void stop() {
        if (state == RUNNING_STATE) {
            System.out.println("电梯停止");
            setState(STOP_STATE);
        }
        if (state == CLOSE_STATE) {
            System.out.println("电梯停止");
            setState(STOP_STATE);
        }
    }
}
